<template>
  <div class="table_con">
    <el-row>
      <tableComponents :isShow="false" @toAdd="openAdd" :isHaveExport="false" :isHavePagination="false" :isShowBottom="false">
        <template v-slot:headRight>
          <div class="fx head-right-icon" v-if="
              $store.state.plugin &&
              $store.state.plugin.jdsc &&
              $store.state.plugin.jdsc.is_open == 1
            " @click="jdproductcate">
            <p><i class="el-icon-data-line"></i>&nbsp;&nbsp;更新京东分类</p>
          </div>
          <div class="fx head-right-icon" @click="jhproductcate" v-if="
              $store.state.plugin &&
              $store.state.plugin.jhgyl &&
              $store.state.plugin.jhgyl.is_open == 1
            ">
            <p><i class="el-icon-coordinate"></i>&nbsp;&nbsp;更新供应链分类</p>
          </div>
        </template>
        <template v-slot:table>
          <el-table :data="data" v-loading="loading" style="width: 100%; margin-bottom: 20px" border row-key="id">
            <el-table-column label="分类名称" min-width="180">
              <template slot-scope="scope">
                <div class="tree_yiji">
                  {{ scope.row.title }}
                  <div class="three_title">
                    {{ scope.row.three }}级栏目(下属分类{{
                      scope.row.length
                    }}个)
                  </div>
                </div>
              </template>
            </el-table-column>

            <el-table-column label="排序" sortable :sort-method="sorta" align="center" width="100">
              <template slot-scope="scope">
                <div>
                  <el-input @change="sortNew(scope.$index, scope.row)" v-model.number="scope.row.sort" autocomplete="off" size="small"></el-input>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="分类图片" min-width="100" align="center">
              <template slot-scope="scope">
                <div class="img_bor">
                  <img :src="$fnc.getImgUrl(scope.row.piclink)" alt />
                </div>
              </template>
            </el-table-column>

            <el-table-column label="是否显示" min-width="80">
              <template slot-scope="scope">
                <el-switch class="zdySwith" :width="80" v-model="scope.row.show" active-color="#13ce66" inactive-color="#999999" active-text="显示" inactive-text="不显示" active-value="1" @change="change_show(scope.row)" inactive-value="0"></el-switch>
              </template>
            </el-table-column>

            <el-table-column label="是否首页展示" min-width="80">
              <template slot-scope="scope">
                <el-switch class="zdySwith" :width="80" v-model="scope.row.is_home" active-color="#13ce66" inactive-color="#999999" active-text="显示" inactive-text="不显示" active-value="1" @change="change_home(scope.row)" inactive-value="0"></el-switch>
              </template>
            </el-table-column>

            <el-table-column label="创建时间" min-width="100" align="center">
              <template slot-scope="scope">{{
                scope.row.created_time | getTimeFormat
              }}</template>
            </el-table-column>

            <el-table-column label="操作" min-width="120" align="center">
              <template slot-scope="scope">
                <el-row class="myblank tl">
                  <div style="padding-left: 20px">
                    <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="open_slide(scope.row)">幻灯片</el-button>

                    <el-button :loading="$store.state.isLoading" size="mini" v-if="scope.row.jd_num" @click="cjjdcp(scope.row)" type="success">采集京东产品</el-button>

                    <el-button :loading="$store.state.isLoading" size="mini" v-if="scope.row.jh_num" @click="cjjhgylcp(scope.row)" type="success">采集聚合供应链产品</el-button>

                    <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="updateMenuLi(scope.row)">编辑</el-button>
                    <br />
                    <el-button :loading="$store.state.isLoading" size="mini" @click="deleteCateShop(scope.row)" type="danger">清空分类商品</el-button>

                    <el-button :loading="$store.state.isLoading" size="mini" @click="deleteMenu(scope.row.id)" type="danger">删除</el-button>
                  </div>
                </el-row>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </tableComponents>

      <el-dialog :close-on-click-modal="false" :modal-append-to-body="false" class="tl size_13" title="商品分类" width="800px" @close="closeDio" :visible.sync="dialogFormVisible">
        <el-form :model="form" ref="form" :rules="rules" label-width="120px">
          <el-form-item label="上级栏目" prop="parent_id">
            <el-col :span="12" class="tl">
              <el-cascader :options="picker_option" :props="optionProps" :show-all-levels="false" v-model="op" size="small" change-on-select style="width: 100%" :placeholder="placeText" @change="handleItemChange"></el-cascader>
            </el-col>
          </el-form-item>
          <el-form-item label="分类标题" prop="title">
            <el-col :span="12">
              <el-input v-model="form.title" autocomplete="off" size="small"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="副标题" prop="description">
            <el-col :span="12">
              <el-input v-model="form.description" autocomplete="off" size="small"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="图片地址" prop="piclink">
            <el-col :span="12" class="tl">
              <el-input v-model="form.piclink" autocomplete="off" disabled clearable class="mar_bottom_5"></el-input>

              <uploadpic :piclink="form.piclink" :width="150" :height="150" :real_width="50" :real_height="50" :is_more="false" @send_pic="onSuccess">
              </uploadpic>
            </el-col>
          </el-form-item>
          <el-form-item label="大图" prop="piclink1">
            <el-col :span="12" class="tl">
              <el-input v-model="form.piclink1" autocomplete="off" disabled clearable class="mar_bottom_5"></el-input>

              <uploadpic :piclink="form.piclink1" :width="281" :height="172" :real_width="375" :real_height="230" :is_more="false" @send_pic="onSuccess1"></uploadpic>
            </el-col>
          </el-form-item>
          <el-form-item>
            <el-button :loading="$store.state.isLoading" type="primary" @click="addMenu('form')" size="mini">立即提交</el-button>
            <el-button :loading="$store.state.isLoading" @click="resetForm('form')" size="mini">重 置</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>

      <el-dialog :close-on-click-modal="false" title="分类幻灯片" width="1200px" v-loading="slide_loading" :visible.sync="dia_slide_show">
        <el-button type="primary" style="float: left; margin-bottom: 20px" :loading="$store.state.isLoading" size="mini" @click="add_slide()">添加幻灯片
        </el-button>
        <el-table ref="multipleTable" :data="slide_list" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark" s style="width: 99.8%">
          <el-table-column label="幻灯片" min-width="100">
            <template slot-scope="scope">
              <div class="cate_img">
                <img :src="$fnc.getImgUrl(scope.row.piclink)" alt />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="排序" min-width="50">
            <template slot-scope="scope">
              <el-input @change="change_slide('sort', scope.row)" v-model="scope.row.sort" autocomplete="off" size="small"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="标题" min-width="150">
            <template slot-scope="scope">{{ scope.row.title }}</template>
          </el-table-column>

          <el-table-column label="链接" min-width="150">
            <template slot-scope="scope">{{ scope.row.links }}</template>
          </el-table-column>

          <el-table-column label="是否显示" min-width="80">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.is_show" @change="change_slide('is_show', scope.row)" :width="50" active-value="1" inactive-value="0" active-color="#13ce66" inactive-color="#999999"></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="80">
            <template slot-scope="scope">
              <el-button type="danger" :loading="$store.state.isLoading" size="mini" @click="edit_slide(scope.row)">编辑</el-button>
              <el-button type="danger" :loading="$store.state.isLoading" size="mini" @click="del_slide(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>

      <el-dialog :close-on-click-modal="false" class="tl size_13" :title="`${is_edit ? '修改' : '添加'}幻灯片`" :visible.sync="dia_addslide_show">
        <el-form :model="addslide_form" ref="form" label-width="120px">
          <el-form-item label="幻灯片标题" prop="title">
            <el-col :span="12">
              <el-input v-model="addslide_form.title" autocomplete="off" size="small"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="是否显示" v-if="is_edit" prop="title">
            <el-col :span="12">
              <el-switch v-model="addslide_form.is_show" :width="80" active-value="1" inactive-value="0" active-color="#13ce66" inactive-color="#99999"></el-switch>
            </el-col>
          </el-form-item>
          <el-form-item label="排序" v-if="is_edit" prop="title">
            <el-col :span="12">
              <el-input v-model="addslide_form.sort" autocomplete="off" size="small"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="图片地址" prop="piclink">
            <el-col :span="12" class="tl">
              <el-input v-model="addslide_form.piclink" autocomplete="off" disabled clearable class="mar_bottom_5"></el-input>
              <uploadpic :piclink="addslide_form.piclink" :width="375" :height="161" :real_width="375" :real_height="161" :is_more="false" @send_pic="onSuccess_add"></uploadpic>
            </el-col>
          </el-form-item>
          <el-form-item label="链接到" prop="links">
            <el-col :span="12">
              <el-input v-model="addslide_form.links" class="mar-input"></el-input>
              <el-input v-model="addslide_form.desc" class="mar-input"></el-input>
            </el-col>
            <el-col :span="5" :offset="1" class="mar_lf_15">
              <LinkMenu @sendRow="getSendRow"></LinkMenu>
            </el-col>
          </el-form-item>
          <el-form-item class="tc bor_top pd_top_10">
            <el-button :loading="$store.state.isLoading" type="primary" @click="add_slide_save()" size="mini">立即提交</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </el-row>

    <el-dialog :close-on-click-modal="false" title="采集" :modal-append-to-body="false" :visible.sync="jh_show" class="size_13" width="500px">
      <el-row class="progress_div">
        <el-col :span="24" class="mar_bottom_25">
          第{{ jh_info.page || 1 }}页采集中，请等待...
        </el-col>
        <el-col :span="24">
          <el-button :loading="$store.state.isLoading" v-if="jh_time" size="medium" type="primary" @click.prevent="cjjhgylcp_jx">
            继续采集
          </el-button>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>
<script>
import uploadpic from "@/components/page/pic/up_pic";
import LinkMenu from "@/components/currency/Link_menu.vue";
import axios from "axios";
import qs from "qs";
var md5 = require("md5");
export default {
  data() {
    return {
      slide_loading: false,
      is_edit: false,
      addslide_form: {
        title: "",
        piclink: "",
        links: "",
        aid: "",
      },
      dia_addslide_show: false,
      cate_id: "",
      slide_list: [],
      dia_slide_show: false,
      data: [],
      xy_down: 0,
      xy_down_text: "全部隐藏",
      hackReset: true,
      add: "",
      op: [],
      option: [],
      optionProps: {
        value: "id",
        label: "title",
        children: "z",
      },
      dialogFormVisible: false,
      form: {
        title: "",
        parent_id: "0",
        piclink: "",
      },
      rules: {
        title: [
          { required: true, message: "请输入商品类别名称", trigger: "blur" },
        ],
        parent_id: [
          { required: true, message: "请添加栏目", trigger: "change" },
        ],
      },
      showImg: false,
      fileList: [],
      placeText: "请选择栏目添加",
      loading: false,
      jh_show: false,
      jh_info: {},
      jh_time: false,
    };
  },
  watch: {},
  computed: {
    picker_option() {
      var arr = JSON.parse(JSON.stringify(this.option));
      if (this.form.three == "二") {
        arr.unshift({ id: "0", title: "顶级分类", show: 1 });
      }
      return arr;
    },
  },
  created() {
    this.getProductList();
  },
  methods: {
    cjjhgylcp_jx() {
      this.jh_time = false;
      this.cjjhgylcp_page();
    },
    cjjhgylcp(row) {
      this.jh_page = 1;
      this.jh_show = true;
      this.jh_info = {
        id: row.jh_num,
        page: 1,
      };
      this.cjjhgylcp_page();
    },
    cjjhgylcp_page() {
      if (this.jh_show != true) {
        return;
      }
      var params = {};
      params = JSON.parse(JSON.stringify(this.jh_info)) || {};
      var uid = localStorage.getItem("adminuid") || "";
      var time = parseInt(new Date().getTime() / 1000) + "";
      var admin_key = localStorage.getItem("admin_key") || "";
      var str = qs.stringify(params);
      var url = "";
      if (str == "") {
        url =
          "admin_key=" +
          admin_key +
          "&headuid=" +
          uid +
          "&timestamp=" +
          time +
          "&meid=" +
          "" +
          "&extra=" +
          "";
      } else {
        url =
          str +
          "&admin_key=" +
          admin_key +
          "&headuid=" +
          uid +
          "&timestamp=" +
          time +
          "&meid=" +
          "" +
          "&extra=" +
          "";
      }
      var arr = url.split("&");
      for (var i in arr) {
        if (arr[i].indexOf("%") >= 0) {
          arr[i] = decodeURIComponent(arr[i]);
        }
      }
      var urlStr = arr.sort().join("&");
      params.sign = md5("@" + urlStr + "@");

      axios
        .post("/api/admin/supply_chain/product", qs.stringify(params), {
          headers: {
            headuid: uid,
            timestamp: time,
            meid: "",
            extra: "",
          },
          timeout: 10000000,
        })
        .then((res) => {
          if (res.data.code == 200) {
            if (!isNaN(res.data.result) && res.data.result !== true) {
              this.jh_info.page = Number(res.data.result) + 1;
              this.cjjhgylcp_page();
            } else {
              this.jh_show = false;
              this.$fnc.alertSuccess({ text: "采集完成" });
            }
          } else {
            this.jh_time = true;
            this.$fnc.alertError(res.data.code_desc, res.data.result);
          }
        });
    },
    jhproductcate() {
      this.$api.getStation.supply_chain_grouping({}).then((res) => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess("操作成功");
          this.getProductList();
        }
      });
    },
    cjjdcp(row) {
      this.$api.getStation
        .jingdong_get_product_sku({ jd_num: row.jd_num })
        .then((res) => {
          if (res.data.code == 200) {
            this.$fnc.alertSuccess("操作成功");
            this.getProductList();
          }
        });
    },
    jdproductcate() {
      this.$api.getStation.jingdong_product_cate({}).then((res) => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess("操作成功");
          this.getProductList();
        }
      });
    },
    editCateOne(row) {
      // this.$confirm(
      //   "确定将" + row.title + "分类 修改未一级分类，请谨慎操作?",
      //   "提示",
      //   {
      //     confirmButtonText: "我已确定",
      //     cancelButtonText: "我再想想",
      //     type: "warning"
      //   }
      // )
      //   .then(() => {
      this.$api.getShops
        .editCateOne({ id: row.id, parent_id: "0" })
        .then((res) => {
          if (res.data.code == 200) {
            this.$fnc.alertSuccess("操作成功");
            this.getProductList();
            this.dialogFormVisible = false;
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      // })
      // .catch(() => {
      //   this.$message({
      //     type: "info",
      //     message: "已取消"
      //   });
      // });
    },
    deleteCateShop(row) {
      this.$confirm(
        "确定清空 " + row.title + "分类 自营与商户所有该分类商品，请谨慎操作?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.$api.getShops
            .clearPraductCateShop({ id: row.id })
            .then((res) => {
              if (res.data.code == 200) {
                this.$fnc.alertSuccess("操作成功");
              } else {
                this.$fnc.alertError(res.data.result);
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    change_slide(type, item) {
      var params = item;
      this.$api.getShops.edit_cate_slide(params).then((res) => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess("编辑成功");
          this.get_slide(this.cate_id);
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },
    getSendRow(row) {
      this.$store.dispatch("getShopsAll", { page: 1, page_size: 10 });
      if (row == null) return false;
      if (!row.disable && row.title == "自定义链接") {
        this.addslide_form.links = "";
        this.addslide_form.desc = "";
        return false;
      }

      if (row.url) {
        this.addslide_form.links = row.url;
        this.addslide_form.desc = row.url_title;
      }

      if (row.url_title == "产品分类" && row.click_title == "供应商分类") {
        this.addslide_form.links =
          "/pages/shop/supplier/supplier?cate=" + row.id;
        this.addslide_form.desc = row.title + "分类供应商店铺";
        return;
      }
      if (row.url_title == "产品分类" && row.click_title != "供应商分类") {
        this.addslide_form.links = "/shop/shopsearch?cate_id=" + row.id;
        this.addslide_form.desc = row.title || "";
      }
      if (row.url_title == "旅游产品分类") {
        this.addslide_form.links = "/tourshop/cate?cate_id=" + row.id;
        this.addslide_form.desc = row.title || "";
      }
      if (row.url_title == "插件管理") {
        this.addslide_form.links = row.url || "";
        this.addslide_form.desc = row.title || "";
      }

      if (row.url_title == "商品选择") {
        this.addslide_form.links =
          "/pages/shop/shopdetail/shopdetail?id=" + row.id;
        this.addslide_form.desc = row.title || "";
      }
      if (row.url_title == "文章添加") {
        this.addslide_form.links =
          "/pages/news/newsdetail/newsdetail?id=" + row.id;
        this.addslide_form.desc = "文章：" + row.title || "";
      }
      if (row.url_title == "资讯分类") {
        this.addslide_form.links = "/news?cate_id=" + row.id;
        this.addslide_form.desc = row.title;
      }
      if (row.url_title == "商品分类2") {
        this.addslide_form.links = "/shop/shopslide?cate_id=" + row.id;
        this.addslide_form.desc = row.title || "";
      }
    },
    del_slide(item) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          var data = { id: item.id };
          this.$api.getShops.del_cate_slide(data).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这些信息。", "success");
              this.get_slide(this.cate_id);
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
              this.get_slide(this.cate_id);
            }
          });
        }
      });
    },

    edit_slide(item) {
      this.is_edit = true;
      this.addslide_form = item;

      this.dia_addslide_show = true;
    },
    add_slide_save() {
      var params = {};
      params.title = this.addslide_form.title;
      params.piclink = this.addslide_form.piclink;
      params.piclink1 = this.addslide_form.piclink1;
      params.links = this.addslide_form.links;
      params.aid = this.addslide_form.aid;
      if (this.is_edit) {
        params.is_show = this.addslide_form.is_show;
        params.sort = this.addslide_form.sort;
        params.id = this.addslide_form.id;
        this.$api.getShops.edit_cate_slide(params).then((res) => {
          if (res.data.code == 200) {
            this.$fnc.alertSuccess("编辑成功");
            this.dia_addslide_show = false;
            this.get_slide(this.cate_id);
            this.addslide_form = {
              title: "",
              piclink: "",
              links: "",
              aid: this.cate_id,
            };
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      } else {
        this.$api.getShops.add_cate_slide(params).then((res) => {
          if (res.data.code == 200) {
            this.$fnc.alertSuccess("添加成功");
            this.dia_addslide_show = false;
            this.get_slide(this.cate_id);
            this.addslide_form = {
              title: "",
              piclink: "",
              links: "",
              aid: this.cate_id,
            };
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      }
    },
    onSuccess_add(pic) {
      this.addslide_form.piclink = pic;
    },
    add_slide() {
      this.is_edit = false;
      this.addslide_form = {
        title: "",
        piclink: "",
        piclink1: "",
        links: "",
        aid: this.cate_id,
      };
      this.dia_addslide_show = true;
    },
    open_slide(item) {
      this.dia_slide_show = true;
      this.cate_id = item.id;
      this.get_slide(item.id);
    },
    get_slide(id) {
      this.slide_loading = true;
      this.$api.getShops.get_cate_slide({ id: id }).then((res) => {
        if (res.data.code == 200) {
          this.slide_loading = false;
          this.slide_list = res.data.result;
        } else {
          this.slide_loading = false;
          this.$fnc.alertError(res.data.result);
        }
      });
    },
    change_home(item) {
      let params = {};
      params.id = item.id;
      params.is_home = item.is_home;
      this.$api.getShops.edit_home_cate(params).then((res) => {
        if (res.data.code == 200) {
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
          this.getProductList();
        }
      });
    },
    change_show(item) {
      let params = {};
      params.id = item.id;
      params.is_show = item.show;
      this.$api.getShops.edit_cate_show(params).then((res) => {
        if (res.data.code == 200) {
          this.getProductList();
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    },
    sorta(a, b) {
      return b - a;
    },
    sortNew(index, row) {
      var params = {};
      params.id = row.id;
      params.sort = row.sort;
      this.$api.getShops.sortInputCat(params).then((res) => {
        if (res.data.code == 200) {
          this.getProductList();
        }
      });
    },
    sortrow(row) {},
    closeDio() {
      this.dialogFormVisible = false;
      this.form = {
        title: "",
        parent_id: "0",
        piclink: "",
      };
      this.showImg = false;
      this.op = [];
    },
    getProductList() {
      this.loading = true;
      var params = {};
      params.parent_id = "";
      this.$api.getShops.get_catetree_all(params).then((res) => {
        if (res.data.code == 200 && res.data.status == 1 && res.data.result) {
          this.option = JSON.parse(JSON.stringify(res.data.result));
          this.data = res.data.result.filter((item) => {
            if (item.z) {
              // eslint-disable-next-line no-self-assign
              item.title = item.title;
              item.length = item.z.length;
              item.z = item.z.filter((it) => {
                if (it.z) {
                  // eslint-disable-next-line no-self-assign
                  it.title = it.title;
                  it.length = it.z.length;
                  it.z = it.z.filter((t) => {
                    if (t.z) {
                      // eslint-disable-next-line no-self-assign
                      t.title = t.title;
                      t.length = t.z.length;
                      t.children = t.z;
                    } else {
                      t.length = 0;
                    }
                    t.three = "三";
                    t.index = 2;
                    return t;
                  });
                  it.children = it.z;
                } else {
                  it.length = 0;
                }

                it.three = "二";
                it.index = 1;
                return it;
              });
              item.children = item.z;
              item.three = "一";
              return item;
            } else {
              item.length = 0;
              item.three = "一";
              item.index = 0;
              return item;
            }
          });
          this.$store.commit("setShopCateList", this.data);
        }
        this.loading = false;
      });
    },
    addMenu(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.dialogFormVisible = false;
          var params = {};
          params = this.form;

          if (params.parent_id == 0 && params.three == "二") {
            params.parent_id = 0;
          }
          if (
            params.piclink == null ||
            params.piclink.lastIndexOf("png") +
              params.piclink.lastIndexOf("jpg") <=
              0
          ) {
            params.piclink = "";
          }
          if (params.id) {
            this.$api.getShops.updateProductCat(params).then((res) => {
              if (
                res.data.code == 200 &&
                res.data.status == 1 &&
                res.data.result
              ) {
                this.$fnc.alertSuccess({ text: "修改成功" }); //成功弹出框
                this.getProductList();
              } else {
                this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
              }
            });
          } else {
            this.$api.getShops.addProductCat(params).then((res) => {
              if (
                res.data.code == 200 &&
                res.data.status == 1 &&
                res.data.result
              ) {
                this.$fnc.alertSuccess({ text: "添加成功" }); //成功弹出框
                this.getProductList();
              } else {
                this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    handleItemChange(val) {
      this.form.parent_id = val[val.length - 1];
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    deleteMenu(id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          var data = { id };
          this.$api.getShops.delProductCat(data).then((res) => {
            if (res.status == 200 && res.data.code == 400) {
              this.$fnc.alertError(res.data.code_desc, res.data.result);
            } else if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.getProductList();
              //刷新页面。。。
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    updateMenuLi(row) {
      this.op = [];
      this.dialogFormVisible = true;
      this.showImg = true;
      this.$api.getShops.findProduct({ id: row.id }).then((res) => {
        if (res.data.code == 200) {
          this.form = res.data.result;
          this.form.three = row.three;
          this.op = res.data.result.up_id.split("@");
        }
      });
    },
    getSortData(da) {
      this.$api.getShops.sortProductCat(da).then((res) => {
        this.getProductList();
      });
    },
    toggle() {
      this.xy_down += 1;
      if (this.xy_down % 2 == 0) {
        this.xy_down_text = "全部隐藏";
      } else {
        this.xy_down_text = "全部显示";
      }
    },

    onSuccess1(pic) {
      this.form.piclink1 = pic;
    },
    onSuccess(pic) {
      this.form.piclink = pic;
      this.showImg = true;
    },

    piclink1(pic) {
      this.form.piclink1 = pic;
      this.showImg = true;
    },

    gethandSwitch(obj) {
      var params = {};
      params = obj;
      this.$api.getShops.updateProductCat(params).then((res) => {
        if (!res.data.result) {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    },
    openAdd() {
      this.form = {
        piclink:"",
        piclink1:"",
      }
      this.dialogFormVisible = true;
    },
  },
  components: {
    uploadpic,
    LinkMenu,
  },
};
</script>
<style scope>
.cate_img {
  width: 150px;
  padding: 10px;
}
.cate_img img {
  width: 100%;
}
</style>
